/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import dto.dlogin;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
//import javax.swing.text.Document;
import javax.swing.JOptionPane;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Element;
import org.w3c.dom.Document;

/**
 *
 * @author HONGPHUOC
 */
public class TaiKhoan {

    public void setTaiKhoan(dlogin tk) {
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            Document doc = builder.newDocument();
            Element taiKhoan = doc.createElement("taikhoan");
            Element host = doc.createElement("host");
            Element port = doc.createElement("port");
            Element username = doc.createElement("username");
            Element pass = doc.createElement("pass");
            Element dataBase = doc.createElement("database");
            host.setTextContent(tk.getHost());
            port.setTextContent(tk.getPort());
            username.setTextContent(tk.getUsename());
            pass.setTextContent(tk.getPass());
            dataBase.setTextContent(tk.getData());
            taiKhoan.appendChild(host);
            taiKhoan.appendChild(port);
            taiKhoan.appendChild(username);
            taiKhoan.appendChild(pass);
            taiKhoan.appendChild(dataBase);
            doc.appendChild(taiKhoan);
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer tran = factory.newTransformer();
            tran.transform(new DOMSource(doc), new StreamResult(new File("taiKhoan.xml")));
        } catch (TransformerException ex) {
            Logger.getLogger(TaiKhoan.class.getName()).log(Level.SEVERE, null, ex);

        } catch (ParserConfigurationException ex) {
            Logger.getLogger(TaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
